﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Cataloger
{
    public partial class FrmZnalezioneAsystent : Form
    {
		#region Fields (2) 

        FrmGlowna fGlow;
        private ListViewColumnSorter lvwColumnSorter;

		#endregion Fields 

		#region Constructors (1) 

        public FrmZnalezioneAsystent(HashSet<Plik> Pliki, HashSet<ArchiwumEntry> Entries,FrmGlowna fgl)
        {
            InitializeComponent();

            lvwColumnSorter = new ListViewColumnSorter();
            this.listView1.ListViewItemSorter = lvwColumnSorter;
            NaglowkiKolumnWyszukiwanie();

            listView1.Items.Clear();
            foreach (Plik p in Pliki)
            {
                p.ShowListViewFileInfo(listView1);
            }
            foreach (ArchiwumEntry a in Entries)
            {
                a.ShowAEListView(listView1);
            }
            toolStripStatusLabel1.Text = "Plików: " + Pliki.Count +" w archiwach:"+ Entries.Count.ToString();
            fGlow = fgl;

        }

		#endregion Constructors 

		#region Methods (5) 

		// Private Methods (5) 

        private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
        {

            // Determine if clicked column is already the column that is being sorted.
            if (e.Column == lvwColumnSorter.SortColumn)
            {
                // Reverse the current sort direction for this column.
                if (lvwColumnSorter.Order == SortOrder.Ascending)
                {
                    lvwColumnSorter.Order = SortOrder.Descending;
                }
                else
                {
                    lvwColumnSorter.Order = SortOrder.Ascending;
                }
            }
            else
            {
                // Set the column number that is to be sorted; default to ascending.
                lvwColumnSorter.SortColumn = e.Column;
                lvwColumnSorter.Order = SortOrder.Ascending;
            }

            // Perform the sort with these new sort options.
            this.listView1.Sort();
        }

        private void NaglowkiKolumnWyszukiwanie()
        {
            listView1.View = View.Details;
            listView1.Columns.Add(new ColHeader("Katalog", 110, HorizontalAlignment.Left));
            listView1.Columns.Add(new ColHeader("Nośnik", 50, HorizontalAlignment.Left));
            listView1.Columns.Add(new ColHeader("Nazwa", 110, HorizontalAlignment.Left));
            listView1.Columns.Add(new ColHeader("Rozmiar", 50, HorizontalAlignment.Left));
            listView1.Columns.Add(new ColHeader("DataUtw", 70, HorizontalAlignment.Left));
            listView1.Columns.Add(new ColHeader("DataMod", 70, HorizontalAlignment.Left));
            listView1.Columns.Add(new ColHeader("DataDost", 70, HorizontalAlignment.Left));
            listView1.Columns.Add(new ColHeader("Rozszerzenie", 110, HorizontalAlignment.Left));
            listView1.Columns.Add(new ColHeader("Atrybuty", 70, HorizontalAlignment.Left));
            listView1.Columns.Add(new ColHeader("Kategoria", 50, HorizontalAlignment.Left));
            listView1.Columns.Add(new ColHeader("Sciezka", 120, HorizontalAlignment.Left));
        }

        private void otwórzFolderToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                ListViewItem item = listView1.SelectedItems[0];
                Plik temp = (Plik)item.Tag;
                if (!temp.UruchomFolder())
                {

                }
            }
            catch { }
        }

        private void otwórzZewnętrznieToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                Plik temp = (Plik)listView1.SelectedItems[0].Tag;
                if (!temp.Uruchom())
                {
                    MessageBox.Show("Nosnik nie podlaczony");

                }
            }
            catch { }
        }

        private void pokazWKataloguToolStripMenuItem_Click(object sender, EventArgs e)
        {
            listView1.PokazPlikwKatalogu(fGlow);
        }

		#endregion Methods 
    }
}
